#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class Solution(object):
    def maxNumOfSubstrings(self, s):
        self.idx_min = {}
        self.idx_max = {}

        # 这里换成list来存
        # self.start_idx_c_map = {}   # {start_idx : c}       # 这个idx对应的char, 是这个char最先出现的idx
        self.start_idx_c_map = []

        self.calc_min_max(s)

        self.merge_c_interval()
        print(self.start_idx_c_map)

    def merge_c_interval(self):
        pass

        l = len(self.start_idx_c_map)

        i = 0
        # while i < l:
        for i in range(l):
            cur_idx, cur_c = l[i]

            for j in (i+1, l):
                next_idx, next_c = l[j]

                is_overlap, end_idx = self.try_merge(cur_c, next_c):
                if is_overlap:

    def try_merge(self, cpre, cnext):
        interval_pre_s, interval_pre_e   = self.idx_min[cpre], self.idx_max[cpre]
        interval_next_s, interval_next_e = self.idx_min[cnext], self.idx_max[cnext]

        if interval_next_s <= interval_pre_e:
            self.self.idx_max[cpre]
            return True, interval_next_e
        else:
            return False, interval_pre_e



    def calc_min_max(self, s):
        idx =  0
        for c in s:
            self.update_c_idx(c, idx)
            idx += 1

    def update_c_idx(self, c, idx):
        if c not in self.idx_min:
            self.idx_min[c] = idx
            # self.start_idx_c_map[idx] = c
            self.start_idx_c_map.append((idx, c))

        self.idx_max[c] = idx


def test():
    s = Solution()
    s.maxNumOfSubstrings("abcdaz")

def main():
    print("start main")
    test()

if __name__ == "__main__":
    main()
